** Store price indices, year-quarter level regressions, 06-15
** JHL 


*************************************
** Set up workspace
*************************************
version 14.0
clear all
set more off
set maxvar 32767, perm 

cd "${path_home}"
adopath + ../programs

cap ssc install estout
cap ssc install parmest
cap ssc install reghdfe
cap ssc install eclplot
cap ssc install blindschemes, replace all

** log using "${path_log}/a01_PIq_stores_reg_0615", text replace

*************************************
** Start work here
*************************************
timer on 1 

use "${path_big_dta}/PI/PIq_mw_0615_master", clear

*************************************
** [1] Unit period FE, key regs
*************************************

** [1.1] Table 1
foreach i in D F M {
	foreach v of varlist logptvc {
		** No controls
		fixed_effects if channel_code=="`i'", ///
		y(`v') x(log_mwq) unit(store_code_uc) year(year) period(quarter) cluster(state) ///
		lags(4) leads(6) time(yq) fe(3) addleads opt(contemp) ///
		savereg(, dir(${path_out}/reg/) name(gp`i'_0615)) ///
		outgraphs(, dir(${path_out}/graphs/) num(1)) 
		
		** Controls
		fixed_effects if channel_code=="`i'", ///
		y(`v') x(log_mwq) unit(store_code_uc) year(year) period(quarter) cluster(state) ///
		controls(loghousingp_zip3_at logunemp logpop logaw) ///
		lags(4) leads(6) time(yq) fe(3) addleads opt(contemp) ///
		savereg(, dir(${path_out}/reg/) name(gp`i'_controls_0615)) ///
		outgraphs(, dir(${path_out}/graphs/) num(1)) 
		
	}
}

** [1.2] Table 2
** cap gen logaw_y2006_qtr1_c = log(avgwklyw_y2006_qtr1_c)	

foreach v of varlist logptvc {
	foreach iact in kaitz_y2006_qtr1_c logaw_y2006_qtr1_c frac_b_25K_5yr_y2009_c kaitz_med_c_5yr_y2009_c logtvct log_est_pop {
		foreach i in F {
			di "`i'"
			fixed_effects if channel_code=="`i'", ///
			y(`v') x(log_mwq) unit(store_code_uc) year(year) period(quarter) ///
			controls(loghousingp_zip3_at logunemp logpop) extra_fe(state#yq) ///
			cluster(state) lags(4) leads(4) interact(, var(`iact') xtype(c) itype(c) symbol(##)) ///
			panel(store_code_uc) time(yq) fe(3) addleads opt(contemp) ///
			savereg(, dir(${path_out}/reg/) name(gp`i'_controls_`iact'_0615_spfe))
		}
	}
}

** [1.3] Table 3
foreach i in D F M {
	foreach q of numlist 1/2 {
		foreach v of varlist logptvc logrealsales logsales {
			fixed_effects if channel_code=="`i'" & kaitz_y2006_qtr1_q2_c==`q', ///
			y(`v') x(log_mwq) unit(store_code_uc) year(year) period(quarter) cluster(state) ///
			controls(loghousingp_zip3_at logunemp logpop logaw) opt(contemp) ///
			lags(4) leads(6) time(yq) fe(3) addleads ///
			savereg(, dir(${path_out}/reg/) name(gp`i'_q`q'_controls_0615)) ///
			outgraphs(, dir(${path_out}/graphs/) num(1)) 
		}
	}
}

** [1.4] Figure 4a 
foreach i in F {
	foreach v of varlist logptvc {	
		** Controls
		fixed_effects if channel_code=="`i'", ///
		y(`v') x(log_mwq) unit(store_code_uc) year(year) period(quarter) cluster(state) ///
		controls(loghousingp_zip3_at logunemp logpop logaw) ///
		lags(4) leads(6) time(yq) fe(3) addleads opt(cumul) ///
		savereg(, dir(${path_out}/reg/) name(gp`i'_controls_0615_bw)) ///
		outgraphs(, dir(${path_out}/graphs/) num(1) commandopt(scheme(plotplain)))
		
	}
}

** Figure 4b
foreach i in F {
	foreach v of varlist logptvc {
		fixed_effects if channel_code=="`i'" & indexing_states == 0, ///
		y(`v') x(log_ann_mwq) unit(store_code_uc) year(year) period(quarter) cluster(state) ///
		controls(loghousingp_zip3_at logunemp logpop logaw) ///
		lags(12) leads(4) time(yq) fe(3) addleads opt(cumul) ///
		savereg(, dir(${path_out}/reg/) name(gp`i'_c_0615_ni_bw)) ///
		outgraphs(, dir(${path_out}/graphs/) num(1) commandopt(scheme(plotplain))) 
	}
}

** Figure 4c 
foreach i in F {
	foreach v of varlist logptvc {
		fixed_effects if channel_code=="`i'" & year >= 2013, ///
		y(`v') x(log_mwq) unit(store_code_uc) year(year) period(quarter) cluster(state) ///
		controls(loghousingp_zip3_at logunemp logpop logaw) ///
		lags(3) leads(4) time(yq) fe(3) addleads opt(cumul) ///
		savereg(, dir(${path_out}/reg/) name(gp`i'_controls_1315_bw)) ///
		outgraphs(, dir(${path_out}/graphs/) num(1) commandopt(scheme(plotplain))) 

	}
}

*************************************
** Close workspace
*************************************
timer off 1
timer list 1
** log close